#ifndef RULELIST_H
#define RULELIST_H

#include "stringlist.h"
#include "pathlist.h"
#include "http_connection.h"
#include "backend_list.h"
#include "configuration.h"

typedef enum {LOCAL_REQUEST_HANDLER, REVERSE_PROXY_REQUEST_HANDLER, FASTCGI_REQUEST_HANDLER} eRequestHandler;
typedef enum {BY_FILE_EXTENSION, BY_PATH, BY_METHOD} eRequestHandlingCriteria;

typedef struct {
	eRequestHandler request_handler;
	eRequestHandlingCriteria request_handling_criteria;

	union {
		stringlist_t file_extensions;
		pathlist_t pathlist;
		char methods[UNLOCK_METHOD + 1];
	} u;

	backend_list_t backend_list;
} rule_t;

typedef struct {
	rule_t *rules;
	size_t size;
	size_t used;
} rulelist_t;

void rulelist_init (rulelist_t *rulelist);
void rulelist_free (rulelist_t *rulelist);

int rulelist_load (rulelist_t *rulelist, const char *host_name, configuration_t *conf);

rule_t *rulelist_match (rulelist_t *rulelist, http_connection_t *http_connection, const char **file_extension);

#endif /* RULELIST_H */
